package net.freebytes.nio;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

/**
 * @description:
 * @author: lin
 * @time: 2024/11/25 17:44
 */
public class TestBuffer {

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        buffer.put("hello world ! ".getBytes(StandardCharsets.UTF_8));
        buffer.flip();
        System.out.println(StandardCharsets.UTF_8.decode(buffer));
        buffer.clear();
//        buffer.compact();
        buffer.put("hello world 22! ".getBytes(StandardCharsets.UTF_8));
        buffer.flip();
        System.out.println(StandardCharsets.UTF_8.decode(buffer));
        buffer.clear();
    }

}
